package com.david.rabbitqm.util;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author David
 * @version V1.0
 * @Package com.david.rabbitqm.util
 * @date 2021/7/17 9:17
 */
public class ChannelUtlis {
    public static Channel getChannel(){
        //连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        //配置连接信息
        factory.setHost("192.168.219.203");
        factory.setVirtualHost("/");
        factory.setUsername("root");
        factory.setPassword("123456");
        factory.setPort(5672);
        try {
            Connection connection = factory.newConnection();
            return connection.createChannel();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (TimeoutException e) {
            e.printStackTrace();
        }
        return null;
    }
}
